from api.input_api import input_data, clear_input_field
from api.login_api import click_button
from tools.logger import log_info
import time
import allure


def query_barcode_and_assert(relation_inquiry_win, barcode: str, assertion_func, name: str='SemiPACK条码'):
    """
    输入条码进行查询，并进行断言
    :param name: 输入数据的名字，默认是“SemiPACK条码”
    :param assertion_func: 断言函数类型
    :param barcode: 输入的条码数据
    :param relation_inquiry_win: 关联查询窗口
    :param
    """
    log_info("🔍 开始查询条码：{}".format(barcode))
    # 清空并输入条码
    clear_input_field(relation_inquiry_win, auto_id="TextBox1",field_name=name)

    with allure.step(f"输入{name}: '{barcode}'"):
        input_data(relation_inquiry_win, barcode, name=name)
    time.sleep(1)

    with allure.step("点击【查询】按钮"):
        log_info("🖱 点击【查询】按钮")
        click_button(relation_inquiry_win, "查询")

    with allure.step("开始执行查询断言"):
        log_info(f"正在执行断言：{assertion_func.__name__}")
        assertion_func()
